home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / libiberty / basename.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-24  |  1.3 KB  |  56 lines

  1. /* Return the basename of a pathname.
  2.    Copyright (C) 1991 Free Software Foundation, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18.  
  19. /*
  20.  
  21. NAME
  22.  
  23.     basename -- return pointer to last component of a pathname
  24.  
  25. SYNOPSIS
  26.  
  27.     char *basename (char *name)
  28.  
  29. DESCRIPTION
  30.  
  31.     Given a pointer to a string containing a typical pathname
  32.     (/usr/src/cmd/ls/ls.c for example), returns a pointer to the
  33.     last component of the pathname ("ls.c" in this case).
  34.  
  35. BUGS
  36.  
  37.     Presumes a UNIX style path with UNIX style separators.
  38. */
  39.  
  40.  
  41. char *
  42. basename (name)
  43.   char *name;
  44. {
  45.   char *base = name;
  46.  
  47.   while (*name)
  48.     {
  49.       if (*name++ == '/')
  50.     {
  51.       base = name;
  52.     }
  53.     }
  54.   return (base);
  55. }
  56.